package com.javasm.crm.controller.gift;


import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.controller.base.BaseController;
import com.javasm.crm.domin.criteria.GiftInfoCriteria;
import com.javasm.crm.domin.entity.gift.*;
import com.javasm.crm.service.giftservice.GoodsService;
import com.javasm.crm.utils.page.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author whl
 * @since 2021-07-12
 */
@RestController
@RequestMapping("Goods")
@Api(value = "GoodsController", description = "查找商品")

public class GoodsController {

	@Autowired
	GoodsService goodsService;


	@GetMapping("getGoods")
	@ApiOperation(value = "条件查询", notes = "条件查询")
	public AxiosResult<PageResult<GoodsVo>> getGoods(GiftInfoCriteria giftInfoCriteria) {
		PageResult<GoodsVo> giftVoPageResult = goodsService.searchGoodsPageByCriteria(giftInfoCriteria);
		return AxiosResult.success(giftVoPageResult);
	}

	@GetMapping("getColor")
	@ApiOperation(value = "查询颜色", notes = "查询颜色")
	public AxiosResult<List<GiftColor>> getColor() {
		List<GiftColor> color = goodsService.findColor();
		return AxiosResult.success(color);
	}

	@GetMapping("getType")
	@ApiOperation(value = "查询类型", notes = "查询类型")
	public AxiosResult<List<GiftType>> getType() {
		List<GiftType> type = goodsService.findType();
		return AxiosResult.success(type);
	}

	@GetMapping("getBrand")
	@ApiOperation(value = "查询颜色", notes = "查询颜色")
	public AxiosResult<List<GiftBrand>> getBrand() {
		List<GiftBrand> brand = goodsService.findBrand();
		return AxiosResult.success(brand);
	}

	@PutMapping("editGood")
	@ApiOperation(value = "修改商品", notes = "修改商品")
	public AxiosResult<Integer> editGood(@RequestBody(required = false) Goods goods) {
		int save = goodsService.editGood(goods);
		return BaseController.toAxiosResult(save);
	}




}
